/**
 * Copyright © 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.withdraw.service;

import java.math.BigDecimal;
import java.util.List;

import com.jeeplus.modules.member.entity.Member;
import com.jeeplus.modules.member.service.MemberService;
import com.jeeplus.modules.withdrawinfo.entity.WithdrawInfo;
import com.jeeplus.modules.withdrawinfo.service.WithdrawInfoService;
import org.apache.poi.openxml4j.opc.TargetMode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.withdraw.entity.Withdraw;
import com.jeeplus.modules.withdraw.mapper.WithdrawMapper;

/**
 * 提现Service
 * @author zhych
 * @version 2021-11-16
 */
@Service
@Transactional(readOnly = true)
public class WithdrawService extends CrudService<WithdrawMapper, Withdraw> {

	@Autowired
	private MemberService memberService;

	public Withdraw get(String id) {
		return super.get(id);
	}
	
	public List<Withdraw> findList(Withdraw withdraw) {
		return super.findList(withdraw);
	}
	
	public Page<Withdraw> findPage(Page<Withdraw> page, Withdraw withdraw) {
		return super.findPage(page, withdraw);
	}
	
	@Transactional(readOnly = false)
	public void save(Withdraw withdraw) {
		super.save(withdraw);
	}
	
	@Transactional(readOnly = false)
	public void delete(Withdraw withdraw) {
		super.delete(withdraw);
	}


	@Transactional(readOnly = false, rollbackFor = Exception.class)
	public void withdraw(Withdraw withdraw, Member member) {
		super.save(withdraw);
		memberService.updatePoint(member);
		// 单独执行修改方法
	}

	@Transactional(readOnly = false, rollbackFor = Exception.class)
	public void over(Withdraw withdraw) {
		super.save(withdraw);
		// 用户金额返还
		Member member = memberService.get(withdraw.getU());
		member.setTcPoint(member.getTcPoint() + Integer.parseInt(withdraw.getMoney()));
		memberService.save(member);
	}
}